import javax.swing.text.html.HTMLDocument;
import java.util.Iterator;
import java.util.Random;
import java.util.Scanner;
import java.util.Arrays;
public class Test {
    public static int feibo(int x){
        if(x <= 0){
            return -1;
        } else if(x == 1){
            return 0;
        } else if(x == 2){
            return 1;
        }
       return feibo(x-1) + feibo(x-2);
    }
    public static void main(String[] args) {
        System.out.println(feibo(5));
        int[] arr = {34,23,56,45,12,78};
        System.out.println(Arrays.toString(arr));
    }
    public static void func1(int[] arr) {
        arr[0] = 12;
    }

    public static void func2(int[] arr) {//让形参指向一个新的数组，不会影响实参
        arr = new int[10];
    }

    public static void main4(String[] args) {
        int[] arr = new int[]{1, 2, 3, 4, 5};
        //func2(arr);
        func1(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        for (int x : arr) {
            System.out.print(x + " ");
        }
        int[] arr1 = {1, 2, 3, 4, 5, 6};
        System.out.println(binarySearch(arr1, 6));
        int[] arr2 = {1, 2, 3, 4};
        reverse(arr);
        System.out.println(Arrays.toString(arr));

    }

    public static void reverse(int[] arr) {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
            left++;
            right--;
        }
    }
        //二分查找
        public static int binarySearch ( int[] arr, int toFind){
            int left = 0;
            int right = arr.length - 1;
            while (left <= right) {
                int mid = (left + right) / 2;
                if (toFind < arr[mid]) {
                    // 去左侧区间找
                    right = mid - 1;
                } else if (toFind > arr[mid]) {
                    // 去右侧区间找
                    left = mid + 1;
                } else {
                    // 相等, 说明找到了
                    return mid;
                }
            }
// 循环结束, 说明没找到
            return -1;
        }
        public static void main3 (String[]args){
            Random random = new Random();
            int a = random.nextInt(0, 101);
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入一个1~100之间的数字");
            long start = System.currentTimeMillis();
            while (scanner.hasNextInt()) {
                int b = scanner.nextInt();
                if (b > a) {
                    System.out.println("猜大了");
                } else if (a > b) {
                    System.out.println("猜小了");
                } else {
                    long end = System.currentTimeMillis();
                    System.out.println("猜对了,用时：" + (end - start));
                }
            }
        }
        //找到在数组中只出现一次的元素
        public static void main2 (String[]args){
            int[] arr = {4, 2, 2, 3, 3};
            int ret = arr[0];
            for (int i = 1; i < arr.length; i++) {
                ret ^= arr[i];
            }
            System.out.println(ret);
        }
        public static void main1 (String[]args){
            int a = 10;
            long b = 100;
            //a = b;//编译失败，可能会发生数据丢失
            b = a;//隐式类型转换
            a = (int) b;//显示类型转换
            //int c = a + b;//a的类型会被强制提升为long
            int d = (int) (a + b);
            byte e = 10;
            byte f = 20;
            //byte g = e+f;//小于32位的运算会被强制提升为int
        }

}